package net.livingflow.web.resource;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

import net.livingflow.model.Pack;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.sun.jersey.api.view.Viewable;

/**
 * @author xueqiang.mi
 * @since 2010-11-28
 */
@Path("/packs")
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class PacksResource extends BaseResource {

	@POST
	@Path("create")
	@Consumes("application/x-www-form-urlencoded")
	public Response postPackForm(@FormParam("name") String name) {
		Pack p = new Pack();
		p.setName(name);
		p.setOwner(getUserName());
		packService.add(p);

		return Response.ok(new Viewable("index", this)).build();
	}

	public List<Pack> getPacks() {
		return packService.list();
	}
}
